package com.weifei.controller;

import com.weifei.core.anotation.WFAutowried;
import com.weifei.core.anotation.WFController;
import com.weifei.core.anotation.WFRequestMapping;
import com.weifei.core.anotation.WFRequestParam;
import com.weifei.core.mvc.WFModelAndView;
import com.weifei.service.MyService;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@WFController
@WFRequestMapping("/wf")
public class MyController {

    @WFAutowried("myService")
    private MyService service;

    @WFRequestMapping("/index")
    public void index(@WFRequestParam("name") String name, HttpServletRequest request
            , HttpServletResponse response) throws IOException {
        response.getWriter().write(service.hello(name));
    }
    @WFRequestMapping("/mv")
    public WFModelAndView mv(@WFRequestParam("name") String name) {
        WFModelAndView mv = new WFModelAndView();
        Map<String, Object> model = new HashMap<>();
        model.put("age", "18");
        model.put("name", name);
        model.put("address", "北京市东城区建国门外大街10086");
        mv.setModel(model);
        mv.setViewName("/hello");
        return mv;
    }
}
